var util = require('../../utils/util.js');
var ajax = require('../../utils/ajax.js');
var common = require('../../utils/common.js');
var PageBase = require('../../common/PageBase.js');
var app = getApp();

Page(common.extendPage(PageBase, {
  data: {
    userType: 0,
    mustLogin: true,
    avatar: '',
    mobile: '',
    nickname: '',
    loading: true
  },
  /**
   * 页面初始化
   */
  onLoad() {
  },
   /**
   * 页面重载
   */
  onShow() {
    if (!!wx.getStorageSync('uid')) {
      this.setData({
        mustLogin: false
      })
      this.getUser();
    }
  },
  /**
   * 页面跳转
   */
  _jumpM(evt) {
    if (this.data.mustLogin) {
      wx.navigateTo({
        url: '/pages/login/index',
      })
    } else {
      this._jump(evt);
    }
  },
  /**
   * 获取用户信息
   */
  getUser() {
    var parmasUrl = '/public/api/user/getUser';
    var paramsData = {
      uid: wx.getStorageSync('uid')
    };
    ajax.P({
      url: parmasUrl,
      data: paramsData,
      success: (res, isLoadcb) => {
        var res = res.data;
        this.setData({
          avatar: res.avatar,
          mobile: res.mobile,
          nickname: res.nickname,
          userType: res.usertype,
          wallet: parseFloat(res.wallet).toFixed(2),
          loading: false
        })
        isLoadcb && isLoadcb();
      },
      fail: (res) => {},
      unneedLoad: true
    })
  }
}));